home *** CD-ROM | disk | FTP | other *** search
- ; Subroutine.: FIX.ASM
- ; Author.....: Bob Doolittle
- ; Date.......: 08/12/84
- ; Notice.....: Copyright 1984, Ashton-Tate, All Rights Reserved.
- ; Notes......: CP/M 80 version.
- ;
- ORG 100H
- ;
- ;BDOS equates
- ;
- SYSTEM EQU 0 ;System entry point
- BDOS EQU 5 ;BDOS entry point
- TBUF EQU 80H ;Default buffer
- FCB EQU 5CH ;Default FCB
- CFS EQU 35 ;Compute file size
- CONIN EQU 1 ;Console in
- CONOUT EQU 2 ;Console out
- PSTR EQU 9 ;Print string
- OPEN EQU 15 ;Open file
- CLOSE EQU 16 ;Close file
- READ EQU 20 ;Read sequential
- WRITE EQU 21 ;Write sequential
- MAKE EQU 22 ;Make file
- DELETE EQU 19 ;Delete file
- READR EQU 33 ;Read random
- ;
- ;ASCII equates
- ;
- CR EQU 13
- LF EQU 10
- ;
- START: XRA A ;Initialize CRLF flag to destroy CRLF
- STA FLG
- LDA FCB+1
- CPI 20H ;Was input file on command line
- JNZ ST2 ;Yes
- LXI D,MES1 ;No, print message and abort
- MVI C,PSTR
- CALL BDOS
- JMP EXIT
- ;
- ST2: LXI D,MES4 ;Print CRLF message
- MVI C,PSTR
- CALL BDOS
- MVI C,CONIN ;Get response
- CALL BDOS
- ANI 5FH ;Make upper case
- CPI 'Y'
- JNZ ST7
- MVI A,1
- STA FLG
- ST7: MVI C,PSTR ;Ask for # of bytes
- LXI D,MES6
- CALL BDOS
- LXI D,CBUF ;Get response
- MVI C,10
- CALL BDOS
- LXI H,CBUF+2
- CALL CONV ;Convert to binary in HL
- CALL DIV ;Divide by 128
- SHLD QUO ;Save quotient and remainder
- CALL CRLF
- CALL CLEAR ;Clear FCB+32-35, FCB+15 and FCB+12
- LXI H,FCB
- LXI D,FCB1
- MVI C,9
- MOVE: MOV A,M ;Move file name and drive from FCB to FCB1
- STAX D
- INX H
- INX D
- DCR C
- JNZ MOVE
- LXI D,FCB
- MVI C,OPEN ;Open file
- CALL BDOS
- INR A ;Was open successful?
- JNZ ST3 ;Yes
- LXI D,MES2 ;No, print message and abort
- MVI C,PSTR
- CALL BDOS
- JMP EXIT
- ST3: LXI D,MES5 ;Working message
- MVI C,PSTR
- CALL BDOS
- LXI D,FCB
- MVI C,CFS ;Compute file size
- CALL BDOS
- LHLD FCB+33 ;Get last record+1
- SHLD REC ;Save locally
- DCX H ;Last record number
- SHLD FCB+33 ;Store it back
- MVI C,READR
- LXI D,FCB
- CALL BDOS ;Read last record
- LXI H,TBUF-1
- MVI C,0 ;Initialize counter
- LOP: INX H ;Scan to 1st EOF mark and keep count
- INR C
- MOV A,M ;Get byte
- CPI 1AH ;Is it EOF?
- JNZ LOP ;No, keep looping
- PUSH B ;Save count to EOF in last record
- CALL CLEAR ;Clear again
- LXI D,FCB1
- MVI C,DELETE ;Delete any possible previous out file
- CALL BDOS
- LXI D,FCB
- MVI C,OPEN ;Re-open the input file
- CALL BDOS
- LXI D,FCB1
- MVI C,MAKE ;Make output file
- CALL BDOS
- ;
- FIRS: LXI D,FCB ;Scan off quotient records
- MVI C,READ
- CALL BDOS
- ORA A
- JZ FST1 ;Read OK
- LXI D,MES3
- MVI C,PSTR
- CALL BDOS
- POP B ;Balance stack
- JMP EXIT
- ;
- FST1: LHLD REC ;Bump record count down
- DCX H
- SHLD REC
- LHLD QUO ;Get DIV result
- MOV A,H
- ORA A ;Have we read sector with remainder ?
- JZ FST2 ;Yes
- DCR H ;No
- SHLD QUO
- LXI D,FCB1 ;Write sector
- MVI C,WRITE
- CALL BDOS
- JMP FIRS
- FST2: MVI A,80H
- ADD L
- MOV L,A ;HL now has filter start address
- FST3: CALL FILTER
- INX H
- MOV A,H
- ORA A
- JZ FST3 ;Filter to end of sector
- LXI D,FCB1
- MVI C,WRITE ;Write to output file
- CALL BDOS
- LOOP: LXI D,FCB
- MVI C,READ ;Read a record to default buffer
- CALL BDOS
- ORA A ;Was read successful?
- JZ LO4 ;Yes
- ERR: LXI D,MES3
- MVI C,PSTR ;No, print message and abort
- CALL BDOS
- POP B ;Balance stack
- JMP EXIT
- ;
- LO4: LHLD REC ;Get record count
- DCX H ;Decrement record count
- SHLD REC ;Save it
- MOV A,H
- ORA L ;Are we at last record?
- JNZ GOAH ;No
- POP B ;Yes, get back count
- LXI H,TBUF
- ;
- LO1: DCR C ;Are we at EOF
- JZ LO2 ;Yes
- CALL FILTER
- INX H
- JMP LO1 ;Loop
- ;
- LO2: LXI D,FCB1
- MVI C,WRITE ;Write last record
- CALL BDOS
- LXI D,FCB1
- MVI C,CLOSE ;Close output file
- CALL BDOS
- EXIT: JMP SYSTEM ;Finished
- ;
- GOAH: LXI H,TBUF
- MVI C,80H ;Initialize record count
- GO1: CALL FILTER ;Scan the record
- INX H
- DCR C ;End of record?
- JNZ GO1 ;No
- LXI D,FCB1
- MVI C,WRITE ;Write record to output file
- CALL BDOS
- JMP LOOP ;Loop to read next record
- ;
- FILTER: MOV A,M
- ANI 7FH ;Strip bit 7
- MOV M,A
- CPI 20H ;Is it < space
- RNC ;No
- MOV B,A ;Save byte
- LDA FLG ;Get CRLF flag
- ORA A ;Are we killing CRLF ?
- JZ FIL1 ;Yes
- MOV A,B ;No, get byte in A
- CPI CR
- RZ ;Don't change
- CPI LF
- RZ ;Don't change
- FIL1: MVI M,20H ;Replace anything < space by space
- RET
- ;
- CONV: LXI D,0 ;Convert # pointed to by HL to binary in HL
- XCHG ;Conversion stops when # < '0' is found
- CONV1: LDAX D
- SUI '0'
- RM
- CPI 10
- CMC
- RC
- INX D
- DAD H
- PUSH H
- DAD H
- DAD H
- POP B
- DAD B
- MOV C,A
- MVI B,0
- DAD B
- JMP CONV1
- ;
- DIV: MVI B,0FFH ;Divide by 128
- LXI D,-128 ;Quotient in H, remainder in L
- DIV1: DAD D
- INR B
- MOV A,H
- ORA A
- JP DIV1
- LXI D,128
- DAD D
- MOV H,B
- RET
- ;
- CLEAR: XRA A ;Zero key fields in FCB
- LXI H,FCB+32
- MOV M,A
- INX H
- MOV M,A
- INX H
- MOV M,A
- INX H
- MOV M,A
- STA FCB+15
- STA FCB+12
- RET
- CRLF: MVI E,CR
- MVI C,CONOUT
- CALL BDOS
- MVI E,LF
- MVI C,CONOUT
- CALL BDOS
- RET
- MES1: DB CR,LF,' USAGE: FIX [d:]<filename.typ>'
- DB CR,LF,'where d is an optional drive designator'
- DB CR,LF,'and filename.typ is the file name and type'
- DB CR,LF,'of the file to be processed. The output'
- DB CR,LF,'file will be named filename.FIX.$'
- MES2: DB CR,LF,'Cannot find file on specified drive.$'
- MES3: DB CR,LF,'Read past EOF.$'
- MES4: DB CR,LF,'Do you want to preserve CRLF''s (Y or N) ? $'
- MES5: DB CR,LF,'Working...$'
- MES6: DB CR,LF,'What is the size of the header (in bytes)? $'
- CBUF: DB 10,0
- DB 0,0,0,0,0,0,0,0,0,0,0,0
- REC DS 2 ;Storage for record count
- QUO: DS 2 ;Storage for quotient and remainder
- FLG: DB 0 ;CRLF flag
- FCB1: DB 0,' FIX'
- REPT 24
- DB 0
- ENDM
-